<?php
require_once (MODEL_PATH . "DAO/connection_mysql.php");
require_once (MODEL_PATH . "DAO/dao_interface.php");

class CvContact implements DAOInterface {
	private $id;
	private $message;
	private $email;
	private $name;
	private $date;
		
	public function getId(){
		return $this->id;
	}	
	public function setId($contactId) {
		$this->id = $contactId;
	}
	
	public function getMessage(){
		return $this->message;
	}	
	public function setMessage($contactMsg) {
		$this->message = $contactMsg;
	}
	
	public function getEmail(){
		return $this->email;
	}	
	public function setEmail($contactEmail) {
		$this->email = $contactEmail;
	}	
	
	public function getName() {
		return $this->name;
	}	
	public function setName($contactName) {
		$this->name = $contactName;
	}
	
	public function getDate() {
		return $this->date;
	}	
	public function setDate($contactDate) {
		$this->date = $contactDate;
	}	
	
	public function __construct() {
		$this->id = 0;
		$this->message = "";
		$this->email = "";
		$this->name = "";
		
		$objDateTime = new DateTime('NOW');		
		$this->date = $objDateTime->format('Y-m-d H:i');
	}	
	
	public function add() {		
		$conn = new ConnectionMySQL();
		$conn->connect();		
		
		$sqlFormat = "
			INSERT INTO cv_contact (message, email, name, date)
			VALUES ('%s', '%s', '%s', '%s');";
		
		//$name = htmlentities($this->getName(), ENT_QUOTES, "UTF-8");
		//$tags = htmlentities($this->getTags(), ENT_QUOTES, "UTF-8");
		
		$query = sprintf($sqlFormat, 
				$conn->escape_string($this->getMessage()),
				$conn->escape_string($this->getEmail()),
				$conn->escape_string($this->getName()),
				$conn->escape_string($this->getDate()));
		
		$conn->query ( $query );		
		$this->setId ($conn->last_insert_id());
		
		$conn->disconnect();
	}
	
	public function delete(){
		
	}
	
	public function update(){
		
	}
	
	public function getAll() {
		
	}
}
?>